﻿CREATE PROCEDURE [dbo].[Forum_ThreadNote_Put]
	@threadNoteId BIGINT,
	@value NVARCHAR(MAX),
	@userId UNIQUEIDENTIFIER
AS
BEGIN
	DECLARE @now DATETIME = GETUTCDATE()

	IF NOT EXISTS(SELECT * FROM [dbo].[forum_ThreadNote] WHERE [ThreadNoteId] = @threadNoteId AND [CreatedBy] = @userId AND DATEDIFF(minute, [CreatedDate], @now) < 1500000)
	BEGIN
		RETURN
	END

	UPDATE [dbo].[forum_ThreadNote]
		 SET [Text] = @value
				,[UpdatedBy] = @userId
				,[UpdatedDate] = @now
	WHERE [ThreadNoteId] = @threadNoteId


	SELECT t.[ThreadId]
				,t.[Name] AS 'Title'
				,s.[HashTag] AS 'SectionHashTag'
				,tn.[ThreadNoteId]
	FROM [dbo].[forum_ThreadNote] AS tn
	INNER JOIN [dbo].[forum_Thread] AS t ON tn.[ThreadId] = t.[ThreadId]
	INNER JOIN [dbo].[forum_Section] AS s ON t.[SectionId] = s.[SectionId]
	WHERE tn.[ThreadNoteId] = @threadNoteId


END